import * as echarts from 'echarts';

const MixType = (list: any, mixNode: HTMLElement) => {
  const letftoption = {
    legend: {},
    tooltip: {
      trigger: 'axis',
      showContent: false,
    },
    dataset: {
      source: list.historylist.slice(0, 10).map((data: any) => {
        return {
          date: data.date,
          cn_conNum: data.cn_conNum,
          cn_conadd: data.cn_conadd,
          cn_cureRate: data.cn_cureRate,
          cn_deathRate: data.cn_deathRate,
        };
      }),
    },
    xAxis: { type: 'category' },
    yAxis: { gridIndex: 0 },
    grid: { top: '55%' },
    series: [
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' },
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' },
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' },
      },
      {
        type: 'line',
        smooth: true,
        seriesLayoutBy: 'row',
        emphasis: { focus: 'series' },
      },
      {
        type: 'pie',
        id: 'pie',
        radius: '30%',
        center: ['50%', '25%'],
        emphasis: {
          focus: 'self',
        },
        label: {
          formatter: '{b}: {@2022} ({d}%)',
        },
        encode: {
          itemName: 'date',
          value: '2022',
          tooltip: '2022',
        },
      },
    ],
  };

  const leftForm = echarts.init(mixNode);

  leftForm.on('updateAxisPointer', function (event: any) {
    const xAxisInfo = event.axesInfo[0];
    if (xAxisInfo) {
      const dimension = xAxisInfo.value + 1;
      leftForm.setOption({
        series: {
          id: 'pie',
          label: {
            formatter: '{b}: {@[' + dimension + ']} ({d}%)',
          },
          encode: {
            value: dimension,
            tooltip: dimension,
          },
        },
      });
    }
  });

  leftForm.setOption(letftoption);
};

export default MixType;
